package com.asdhawaii.otello.board;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
 * Tests the Square class.
 * 
 * @author Branden Ogata
 *
 */

public class TestSquare
{
  /**
   * Tests the methods of the Square class.
   * 
   */
  
  @Test
  public void test()
  {
    // The Square instances to test
    Square empty = new Square();
    Square white = new Square(SquareContents.WHITE);
    Square black = new Square(SquareContents.BLACK);
    Square change = new Square();
    
    // Test getter
    assertEquals("Empty constructor should create empty Square", 
                 empty.getContents(), SquareContents.EMPTY);
    assertEquals("Test getContents for white piece", white.getContents(), SquareContents.WHITE);
    assertEquals("Test getContents for black piece", black.getContents(), SquareContents.BLACK);

    // Test setter
    assertEquals("Square change should start empty", change.getContents(), SquareContents.EMPTY);
    change.setContents(SquareContents.WHITE);
    assertEquals("Square change should become white", change.getContents(), SquareContents.WHITE);

    // Test the is[Corner|A|C|X]Square methods
    Square temp = new Square();
    temp.setName("00");
    assertTrue("Square 00 should be corner", temp.isCorner());
    assertFalse("Square 00 should not be X square", temp.isXSquare());
    assertFalse("Square 00 should not be A square", temp.isASquare());
    assertFalse("Square 00 should not be C square", temp.isCSquare());
    
    temp.setName("01");
    assertTrue("Square 01 should be C square", temp.isCSquare());
    assertFalse("Square 01 should not be corner", temp.isCorner());
    assertFalse("Square 01 should not be X square", temp.isXSquare());
    assertFalse("Square 01 should not be A square", temp.isASquare());
    
    temp.setName("02");
    assertTrue("Square 02 should be A square", temp.isASquare());
    assertFalse("Square 02 should not be corner", temp.isCorner());
    assertFalse("Square 02 should not be X square", temp.isXSquare());
    assertFalse("Square 02 should not be C square", temp.isCSquare());
    
    temp.setName("11");
    assertTrue("Square 11 should be X square", temp.isXSquare());
    assertFalse("Square 11 should not be corner", temp.isCorner());
    assertFalse("Square 11 should not be A square", temp.isASquare());
    assertFalse("Square 11 should not be C square", temp.isCSquare());
    
    // Test equals
    assertTrue("Test equals with identical instances", empty.equals(empty));
    assertTrue("Test equals with equal instances", white.equals(change));
    assertFalse("Test equals with unequal instances", black.equals(change));
    
    // Test hashCode
    assertEquals("Test hashCode with identical instances", black.hashCode(), black.hashCode());
    assertEquals("Test hashCode with equal instances", white.hashCode(), change.hashCode());
  }
}
